home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9148 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  50 lines

  1. Path: newshub.ccs.yorku.ca!news
  2. From: KuMan <" yu133496"@yorku.ca>
  3. Newsgroups: comp.lang.c++
  4. Subject: character strings read-in problem!
  5. Date: Wed, 28 Feb 1996 17:56:18 -0500
  6. Organization: York University, Ontario, Canada
  7. Message-ID: <4h2mkr$5au@sunburst.ccs.yorku.ca>
  8. NNTP-Posting-Host: kirk07.slip.yorku.ca
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (Win95; I)
  13.  
  14. hello all:
  15.  
  16.     I'm trying to read in strings from a file and put them in an array of 26 different cells 
  17. according to their order alphabetically.
  18.  
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. void main(){
  23.  
  24. FILE *input;
  25. char name[20];
  26. char *stop_word[26];
  27.  
  28. input = fopen("QQ.txt", "r");
  29. while(!feof(input)){
  30.     fscanf(input, "%s", name);
  31.     stop_word[((name[0] >= 97)? name[0]-96 : name[0]%64)] = name;
  32. }
  33. printf("%s \n", stop_word[1]);
  34. printf("%s \n", stop_word[3]); 
  35. }
  36. fclose(input);
  37. }
  38.  
  39. "QQ.txt"
  40.  apple boy cow duck eagle
  41.  
  42. But both of the 2 print statements print out "eagle", they suppose to be "apply" and "boy" 
  43. accordingly.........
  44.  
  45. what went wrong???????
  46.  
  47. Thank You
  48. Kuman
  49. yu133496@yorku.ca
  50.